package com.wanxi.treeset;

import java.util.Comparator;
import java.util.Set;
import java.util.TreeSet;

public class StudentAgrConstructorTest {
    public static void main(String[] args) {
        Set<Student> set = new TreeSet<>(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                int res = o1.getAge() - o2.getAge();
                return res == 0 ? o1.getName().compareTo(o2.getName()) : res;
            }
        });
        set.add(new Student("zhangsan", 11));
        set.add(new Student("lisi", 13));
        set.add(new Student("wangwu", 17));
        set.add(new Student("lucyb", 14));
        set.add(new Student("lucya", 14));
        set.add(new Student("xiaoming", 12));
        for (Student s : set
        ) {
            System.out.println(s);
        }
    }
}
